package xyz.shenmegui.foodcheckserver.http;

import java.util.HashMap;
import java.util.Map;

public class HttpResponse extends HashMap<String, Object> {

    public HttpResponse() {
        put("code", 200);
        put("msg", "success");
    }

    public static HttpResponse error() {
        return error(500, "服务器开小差啦");
    }

    public static HttpResponse error(String msg) {
        return error(500, msg);
    }

    public static HttpResponse error(int code, String msg) {
        HttpResponse r = new HttpResponse();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static HttpResponse ok(String msg) {
        HttpResponse r = new HttpResponse();
        r.put("msg", msg);
        return r;
    }

    public static HttpResponse ok(Map<String, Object> map) {
        HttpResponse r = new HttpResponse();
        r.putAll(map);
        return r;
    }

    public static HttpResponse okWithData(Object o) {
        HttpResponse r = new HttpResponse();
        r.put("data", o);
        return r;
    }

    public static HttpResponse ok() {
        return new HttpResponse();
    }

    public HttpResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
